import random

DICTBASE = {
    "numbers": ["3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"],  # 13
    "flowers": ["♠", "♣", "♥", "♦"]  # 4
}


class Poker:
    def __init__(self, card_nums: int = 1, person_nums: int = 4):
        self.card_nums = card_nums
        self.person_nums = person_nums
        self.poker_lists = []
        self.person_poker_lists = []
        self.start()

    def start(self):
        while True:
            print("=" * 30, "请选择1生成 2显示 3发牌 4玩家乱 5洗牌 6玩家顺 7结束", "=" * 30)
            num = input("请选择：")
            if num == "1":
                print("生成牌")
                self.build_poker()
            elif num == "2":
                print("显示牌")
                self.show_poker(self.poker_lists)
            elif num == "3":
                print("发牌")
                self.deal_poker()
            elif num == "4":
                print("显示玩家的牌")
                self.show_person_poker()
            elif num == "5":
                self.shuffle_poker()
                print("洗牌")
            elif num == "6":
                self.show_person_posker_order()
                print("显示玩家整理后的牌")
            elif num == "7":
                print("结束")
                break
            else:
                print("请重新输入")

    def build_poker(self):
        for card in range(self.card_nums):
            for index_number, number in enumerate(DICTBASE['numbers']):
                for index_flower, flower in enumerate(DICTBASE['flowers']):
                    # print("%02d%02d" % (index_number,index_flower))
                    self.poker_lists.append("%02d%02d" % (index_number, index_flower))

    def show_poker(self, poker_lists: list):
        for poker in poker_lists:
            flower = DICTBASE["flowers"][int(poker[2:])]
            number = DICTBASE["numbers"][int(poker[:2])]
            print("%s%s" % (flower, number), end="\t")

    def shuffle_poker(self):
        random.shuffle(self.poker_lists)

    def deal_poker(self):

        for index_person in range(self.person_nums):
            temp = []
            for index_poker in range(len(self.poker_lists)):
                if index_poker % self.person_nums == index_person:
                    temp.append(self.poker_lists[index_poker])
            self.person_poker_lists.append(temp)

    def show_person_poker(self):
        for person_idex, person_poker in enumerate(self.person_poker_lists):
            print("第%d个人的牌：" % (person_idex + 1), "")
            self.show_poker(person_poker)
            print("")

    def show_person_posker_order(self):
        for person_idex, person_poker in enumerate(self.person_poker_lists):
            print("第%d个人的牌：" % (person_idex + 1), "")
            self.show_poker(sorted(person_poker))
            print("")


if __name__ == '__main__':
    poker = Poker(2);
    poker.build_poker()
